<template>
  <div class="app-container ">
    <el-form ref="form" size="mini" :model="form" :rules="rules" label-width="180px">
      <el-tabs v-model="activeName">
        <el-tab-pane style="padding-top:10px" label="打印机设置" name="打印机设置">
          <el-row>
            <el-col :span="24">
              <el-form-item label="打印机类型" prop="pinpai">
                <el-select v-model="form.pinpai" style="width:100%" filterable clearable placeholder="请选择">
                  <el-option v-for="(item,i) in PinpaiType" :key="i" :label="item.key" :value="item.val" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="USER">
                <el-input v-model="form.user" auto-complete="off" clearable placeholder="请输入USER" />
                <div class="help-block">飞鹅云后台注册用户名</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="UKEY">
                <el-input v-model="form.ukey" auto-complete="off" clearable placeholder="请输入UKEY" />
                <div class="help-block">飞鹅云后台登录生成的UKEY</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="打印机编号">
                <el-input v-model="form.sn" auto-complete="off" clearable placeholder="请输入打印机编号" />
                <div class="help-block">打印机编号9位,查看飞鹅打印机底部贴纸上面的打印机编号</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="打印机key">
                <el-input v-model="form.key" auto-complete="off" clearable placeholder="请输入打印机key" />
                <div class="help-block">查看飞鹅打印机底部贴纸上面的打印机key</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="打印联数">
                <el-input v-model="form.times" auto-complete="off" clearable placeholder="请输入打印联数" />
                <div class="help-block">同一订单，打印的次数</div>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="状态">
                <el-radio-group v-model="form.status">
                  <el-radio label="0">关闭</el-radio>
                  <el-radio label="1">开启</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
      <el-form-item>
        <el-button size="mini" type="primary" @click="submit">保存设置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: 'printerindex',
  components: {
  },
  data() {
    return {
      form: {},
      PinpaiType: {},
      loading: false,
      activeName: '打印机设置',
      rules: {}
    }
  },
  mounted() {
    this.$api.post('/printer/getField').then(res => {
      this.PinpaiType = res.data.PinpaiType
    })
    this.$api.post('/printer/getInfo').then(res => {
      this.form = JSON.stringify(res.data) == '[]' ? {} : res.data
    })
  },
  methods: {
    submit() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$api.post('/printer/update', this.form).then(res => {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
          }).catch(() => {
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
